package com.yyx.up.analysis.fd.mapper;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;

import java.io.IOException;

/**
 * Description: 分析数据的mapper
 * @Author: yyx
 * @Create: 2023/5/5 19:44
 * @Version: 8
 */
public class AnalysisTextMapper extends TableMapper<Text,Text> {
    @Override
    protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException {
        String rowkey = Bytes.toString(key.get());//Bytes.toString解析数据
        //5_02_20221025055816_19683537146_0571_0
        String[] values = rowkey.split("_");
        String film = values[1];
        String tel = values[3];
        String watchtime = values[2];
        String duration = values[4];

        String year = watchtime.substring(0,4);
        String month = watchtime.substring(0,6);
        String date = watchtime.substring(0,8);

        // 观影数据 - 年
        context.write(new Text(film + "_" + year),new Text(duration));
        // 观影数据 - 月
        context.write(new Text(film + "_" + month),new Text(duration));
        // 观影数据- 日
        context.write(new Text(film + "_" + date),new Text(duration));
    }
}
